package com.nd.mobile.study.view;

import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.nd.mobile.study.R;
import com.nd.mobile.study.common.App;
import com.nd.mobile.study.common.BaseActivity;
import com.nd.mobile.study.common.SimpleAsyncTask;
import com.nd.mobile.study.common.constants.BundleConstants;
import com.nd.mobile.study.domain.HomeworkARecord;
import com.nd.mobile.study.domain.HomeworkARecordDetail;

public class HomeworkRecordDetailActivity extends BaseActivity {

	private TextView		mTVATitle;
	private TextView		mTVQTitle;
	private TextView		mTVQContent;
	private TextView		mTVScore;
	private TextView		mTVReviewerName;
	private TextView		mTVReviewerNote;

	private HomeworkARecord	mRecord;

	@Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.homework_a_record_detail);
	}

	@Override
	protected void initViews() {
		super.initHeader();
		mHeaderTitleTv.setText("作业记录");
		mHeaderBtnHome.setVisibility(View.VISIBLE);
		mTVATitle = (TextView) findViewById(R.id.homework_a_record_detail_a_title);
		mTVQTitle = (TextView) findViewById(R.id.homework_a_record_detail_q_title);
		mTVQContent = (TextView) findViewById(R.id.homework_a_record_detail_a_content);
		mTVScore = (TextView) findViewById(R.id.homework_a_record_detail_score);
		mTVReviewerName = (TextView) findViewById(R.id.homework_a_record_detail_reviewer_name);
		mTVReviewerNote = (TextView) findViewById(R.id.homework_a_record_detail_reviewer_note);
	}

	@Override
	protected void onAfterCreate(Bundle savedInstanceStat) {
		getIntentData();
		showDetail();
	}

	private void getIntentData() {
		mRecord = (HomeworkARecord) getIntent().getSerializableExtra(BundleConstants.HOMEWORK_A_RECORD);
	}

	private void showDetail() {
		mLoading.p();
		new GetDetailTask(this).execute();
	}

	private class GetDetailTask extends SimpleAsyncTask<Void, Void, HomeworkARecordDetail> {

		public GetDetailTask(Context context) {
			super(context);
		}

		@Override
		protected HomeworkARecordDetail onLoad(Void... params) throws Exception {
			return mRecord.getDetail(App.getInstance().getUser());
		}

		@Override
		protected void onUI(HomeworkARecordDetail detail) {
			mTVATitle.setText("作业回答标题:"+detail.getTitle());
			mTVQTitle.setText("课程作业标题:"+detail.getHomeworkTitle());
			mTVQContent.setText(Html.fromHtml(detail.getNote()));
			mTVScore.setText("得分:"+detail.getScore());
			mTVReviewerName.setText("评分老师:"+detail.getReviewerName());
			mTVReviewerNote.setText(Html.fromHtml("评语:"+detail.getReviewerNote()));
			mLoading.v();
		}

	}
}
